package org.example.ai_chat.service.impl;

import org.example.ai_chat.mapper.AiMemoryMapper;
import org.example.ai_chat.mapper.AiSessionMapper;
import org.example.ai_chat.pojo.ai_memory;
import org.example.ai_chat.pojo.ai_session;
import org.example.ai_chat.service.SessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SessionServiceImpl implements SessionService {
    @Autowired
    private AiSessionMapper aiSessionMapper;
    @Autowired
    private AiMemoryMapper aiMemoryMapper;

    @Override
    public List<List<ai_memory>> getUserMemoryById(int id) {
        List<ai_session> sessions=aiSessionMapper.getSessionByUserId(id);
        List<List<ai_memory>> memoryList=new ArrayList<>();
        for (ai_session session:sessions) {
            memoryList.add(aiMemoryMapper.selectByConversationId(Integer.toString(session.getId())));
        }

        return memoryList;
    }

    @Override
    public int setSession(ai_session session) {
        aiSessionMapper.insertSession(session);
        return session.getId();
    }
}